package cn.zhuizikejithreeig.com.adapter;

import android.support.v7.widget.RecyclerView;
import android.util.SparseArray;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

/**
 * Created by 赵航 on 2017/7/24.
 */

public class BasicViewholder extends RecyclerView.ViewHolder {
    //缓存itemView内部的子View
    private SparseArray<View> mViews;
    private View              mConvertView;
    public BasicViewholder(View itemView) {
        super(itemView);
        mConvertView = itemView;
        mViews = new SparseArray<>();
    }
    /**
     * 加载layoutId视图并用LGViewHolder保存
     *
     * @param parent   将自己的view返回。现在所有
     * @param layoutID
     * @return
     */
    public static BasicViewholder getViewHolder(ViewGroup parent, int layoutID) {
        View view = LayoutInflater.from(parent.getContext()).inflate(layoutID, parent, false);
        return new BasicViewholder(view);
    }
    public View getView(int id) {
        View view = mViews.get(id);
        if (view == null) {
            view = mConvertView.findViewById(id);
            mViews.put(id, view);
        }
        return view;
    }
}

